package net.zoneland.zrdp.common.utils.bean;

import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.Validator;

/**
 * bean对象属性验证
 *
 * @author zonevue
 */
public class BeanValidators
{
    private BeanValidators() {
        throw new IllegalStateException("BeanValidators Utility class");
    }
    public static void validateWithException(final Validator validator, final Object object, final Class<?>... groups)
            throws ConstraintViolationException {

        final Set<ConstraintViolation<Object>> constraintViolations = validator.validate(object, groups);
        if (!constraintViolations.isEmpty()) {
            throw new ConstraintViolationException(constraintViolations);
        }

    }

}
